package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.ihelpuoo.lang.ObjectUtils;
import org.ihelpuoo.orm.ObjectRule;
import org.ihelpuoo.orm.filter.FieldFilter;

public abstract class SaveArrayFieldHandler extends SaveCollectionFieldHandler
{

	public SaveArrayFieldHandler(ObjectProcessor beanHandler)
	{
		super(beanHandler);
	}

	@Override
	protected void processWithoutExceptionHandle(ObjectRule br, Field f, Object src, Object obj,
			FieldFilter actived, FieldFilter locked, String prefix) throws Exception
	{
		Method getter = ObjectUtils.getGetter(obj.getClass(),f);
		Object[] v = (Object[])getter.invoke(obj,(Object[])null);
		if (null == v || v.length == 0)
			return;

		Object subSrc = prepareSubSource(br,f,src);
		ObjectRule subRule = processor.manual.getRule(br.getComponentType(f));
		for (int i = 0; i < v.length; i++)
		{
			processor.insert(subRule,subSrc,v[i],null,null);
		}
	}
}
